import {
    Index
} from './index.model'
const index = new Index()
Component({
    data: {
        active: 0,
        list: [{
                "pagePath": "/pages/index/index",
                "iconPath": "/images/tabbar-index.png",
                "selectedIconPath": "/images/tabbar-index-active.png",
                "text": "首页"
            },
            {
                "pagePath": "/pages/service/service",
                "iconPath": "/images/tabbar-service.png",
                "selectedIconPath": "/images/tabbar-service-active.png",
                "text": "生活服务"
            },
            {
                "pagePath": "/pages/order/order",
                "iconPath": "/images/tabbar-order.png",
                "selectedIconPath": "/images/tabbar-order-active.png",
                "text": "订单"
            },
            {
                "pagePath": "/pages/my/my",
                "iconPath": "/images/tabbar-my.png",
                "selectedIconPath": "/images/tabbar-my-active.png",
                "text": "我的"
            }
        ],
        messageNumber: ''
    },
    methods: {
        onSwitchTab(e) {
            this.setData({
                active: e.detail
            })
            wx.switchTab({
                url: this.data.list[e.detail].pagePath
            })
        },
        init() {
            const page = getCurrentPages().pop()
            this.setData({
                active: this.data.list.findIndex(item => item.pagePath === `/${page.route}`)
            })
        }
    },
    lifetimes: {
        attached() {
            let that = this
            // 在组件实例进入页面节点树时执行
            // index.getMessageNumber().then((res) => {
            //     if (res.data > 0) {
            //         that.setData({
            //             messageNumber: res.data
            //         })
            //     }
            // })
        }
    },
})